import Mock from 'better-mock'
import { loginResSuccess, loginResFailForPasswordErr, loginResFailForUsernameNotExist, TOKEN, infoResSuccess, authException } from './template/user'

export const USERNAME = 'root'
export const PASSWORD = '123456'

Mock.mock('/auth/login', 'POST', function(options) {
    const body = JSON.parse(options.body)
    const { username, password } = body
    console.log(body)
    if (username === USERNAME) {
        if (password === PASSWORD) {
            return loginResSuccess
        } else {
            return loginResFailForPasswordErr
        }
    } else {
        return loginResFailForUsernameNotExist
    }
})

Mock.mock('/auth/info', 'GET', function(options) {
    const { headers } = options
    const token = headers[import.meta.env.VITE_TOKEN]
    if (token === TOKEN) {
        return infoResSuccess
    } else {
        return authException
    }
})